<template>
  <div>
    <a-card :bordered="false">
      <f-search-form :more="false" @searchHandler="searchHandler">
        <f-search-form-item label="标题" name="activityTitle"/>
        <f-search-form-item label="分类" type="select" name="typeId" :data="api.type.list" label-key="typeName" value-key="typeId"/>
      </f-search-form>
      <f-table ref="table" size="default" rowKey="activityId" :scroll="scroll" :columns="columns" :multiple="false" :operator="operator" :params="queryParam" :api="api.inteActivity" handler="shopActivityListHandler">
          <span slot="coverImage" slot-scope="text, record, index">
          <f-images :value="record.coverImage"/>
        </span>
        <span slot="activityTitle" slot-scope="text, record, index">
         <ellipsis :length="40" tooltip :lines="4">
          {{record.activityTitle}}
          </ellipsis>
        </span>
        <span slot="sendStatus" slot-scope="text, record, index">
          <a-switch v-model="record.activityState==1" checkedChildren="已发布" unCheckedChildren="未发布" @change="(checked) => setStatus(checked,record)"/>
        </span>
        <span slot="recommend" slot-scope="text, record, index">
          <a-switch v-model="record.recommend==1" checkedChildren="已推荐" unCheckedChildren="未推荐" @change="(checked) => setRecommend(checked,record)"/>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.modal.handleShow(record)">编辑</a>
            <a-divider type="vertical"/>
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="$auth('table.delete')">
                <a href="javascript:;" @click="$refs.table.remove(record.activityId)">删除</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <inte-activity-drawer ref="modal"></inte-activity-drawer>
    </a-card>
  </div>
</template>

<script>

  import InteActivityDrawer from './inte_activity_drawer'
  import Ellipsis from '../../../../components/Ellipsis/Ellipsis'

  export default {
    name: 'TableList',
    components: {
      InteActivityDrawer,
      Ellipsis
    },
    data() {
      let me = this
      return {
        //列表初始化查询参数
        scroll: { x: 1350 },
        queryParam: {},
        nowContentId: '',
        // 表头
        columns: [
          {
            title: '#',
            width: '60px',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '封面图',
            align: 'center',
            width: '100px',
            scopedSlots: { customRender: 'coverImage' }
          },
          {
            title: '标题',
            scopedSlots: { customRender: 'activityTitle' }
          },
          {
            title: '分类',
            align: 'center',
            width: '90px',
            dataIndex: 'typeName'
          },
          {
            title: '发布状态',
            align: 'center',
            dataIndex: 'contentState',
            scopedSlots: { customRender: 'sendStatus' }
          },
          {
            title: '推荐状态',
            align: 'center',
            dataIndex: 'recommend',
            scopedSlots: { customRender: 'recommend' }
          },
          {
            title: '地区',
            align: 'center',
            width: '180px',
            dataIndex: 'areaName'
          },
          {
            title: '电话',
            align: 'center',
            dataIndex: 'activityMobile'
          },
          {
            title: '标签',
            align: 'center',
            width: '160px',
            dataIndex: 'activityTag'
          },
          {
            title: '查看数',
            align: 'center',
            width: '80px',
            dataIndex: 'viewCount'
          },
          {
            title: '操作',
            dataIndex: 'action',
            fixed: 'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
        //操作按钮
        operator: [
          {
            name: '添加',
            icon: 'plus',
            that: this,
            handler: function(table, that) {
              that.$refs.modal.handleShow()
            }
          },
          {
            name: '删除',
            icon: 'delete',
            batch: true,
            handler: function(table) {
              table.remove()
            }
          }
        ]
      }
    },
    created() {

    },
    methods: {
      searchHandler(params) {
        this.$refs.table.refresh(true, params)
      },
      setStatus(check, record) {
        this.http.post(this, {
          url: this.api.inteActivity.setState,
          data: {
            ids: record.activityId,
            activityState: Number(check)
          },
          success(me, data) {
            record.activityState = data
          }
        })
      },
      setRecommend(check, record) {
        this.http.post(this, {
          url: this.api.inteActivity.setRecommend,
          data: {
            ids: record.activityId,
            recommend: Number(check)
          },
          success(me, data) {
            record.recommend = data
          }
        })
      }
    }

  }
</script>
